const BehaviorAll = require("../../../behaviors/behavior_all.js");
const ServiceOrder = require("../../../service/service_order.js");

Component({
  /**
   * behaviors
   */
  behaviors: [BehaviorAll],
  /**
   * 页面的初始数据
   */
  data: {
    /**
     * 待付款=1
     * 待审核=2
     * 待发货=3
     * 已发货=4
     * 已完成=5
     */
    orderState:null,
    /**
     * 订单数据格式：
     */
    orders: []
  },

  methods: {
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      const _this = this;
      const state = Number(options.state);
      _this.setData({
        orderState: state,
      });
      //
      ServiceOrder.list(state, function (data) {
        _this.setData({ orders: data.records })
      });
    },

    /**
     * 选择Tab
     */
    onTab: function (e) {
      const _this = this;
      // 处理状态参数
      let state = e.currentTarget.dataset.state;
      if (state) {
        state = Number(state);
      } else {
        state = '';
      }
      _this.setData({
        orderState: state,
      });
      // 申请列表
      ServiceOrder.list(state, function (data) {
        _this.setData({ orders: data.records })
      });
    }
  }

})